package person.bing.fbcloud.leetcode;

/**
 * @author: mengfanbing
 * @date: 2020/8/10 9:35
 */
public class Q696 {
    public static void main(String[] args) {
        String param = "00110";
        int i = countBinarySubstrings(param);
        System.out.println(i);
    }

    public static int countBinarySubstrings(String s) {
        int ans = 0;
        int length = s.length();
        for(int i=0;i<length-1;i++){
            for (int j=i+1;j<length;j++){
                int subLength = j-i+1;
                int remain = subLength % 2;
                if (remain == 0){
                    String substring = s.substring(i, j+1);
                    int half = subLength / 2;
                    String value = substring.substring(half, half + 1);
                    boolean temp = true;
                    for (int z=0;z<subLength;z++){
                        if (z<half && substring.substring(z,z+1).equals(value)){
                            temp = false;
                            break;
                        }
                        if(z>half && false == (substring.substring(z,z+1).equals(value))){
                            temp = false;
                            break;
                        }
                    }
                    if (temp){
                        ans++;
                    }
                }
            }
        }
        return ans;
    }
}
